package org.budo.cmbc.direct.sdk.entity.ryb;

import java.util.ArrayList;
import java.util.List;

import org.budo.cmbc.direct.sdk.entity.AbstractCmbcDirectResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 如意宝申购/赎回明细查询
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
public class MELERybProdJnlQueryResponse extends AbstractCmbcDirectResponse {
    private static final long serialVersionUID = -437443206310694819L;

    /**
     * 总笔数
     */
    private String totalCount;

    /**
     * 明细列表
     */
    private List<MELERybProdJnlRecord> recordList;

    public MELERybProdJnlQueryResponse(String channelJnlNo, String responseJson) {
        super(channelJnlNo, responseJson);

        JSONObject jsonObj = JSON.parseObject(responseJson);

        this.totalCount = jsonObj.getString("TotalCount");

        JSONArray jsonArr = jsonObj.getJSONArray("List");

        this.recordList = new ArrayList<>();

        if (jsonArr != null && jsonArr.size() > 0) {
            JSONObject jsonData = (JSONObject) jsonArr.get(0);

            MELERybProdJnlRecord record = new MELERybProdJnlRecord();
            record.setOrderNo(jsonData.getString("OrderNo")).setProdSubId(jsonData.getString("ProdSubId")).setProdSubName(jsonData.getString("ProdSubName")).setReCode(jsonData.getString("ReCode")).setReMsg(jsonData.getString("ReMsg")).setStatus(jsonData.getString("Status")).setSummary(jsonData.getString("Summary")).setTransAmount(jsonData.getString("TransAmount")).setTransCode(jsonData.getString("TransCode")).setTransDate(jsonData.getString("TransDate")).setTransShare(jsonData.getString("TransShare"));

            this.recordList.add(record);
        }
    }
}
